
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
%>
<html>
<head>
    <title>Title</title>
    <jsp:include page="../../common/css_js.jsp" />
</head>
<body>
<div class="container">
    <h3>用户信息</h3><a class="btn btn-success" href="${pageContext.request.contextPath}/goods/getAllByPage">返回商品页面</a>
    <table class="table">
        <thead>
        <tr>
            <th>用户编号</th>
            <th>用户名称</th>
            <th>用户昵称</th>
            <th>联系电话</th>
            <th>收货地址</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${Users}" var="one">
            <tr id="b_${one.userId}">
                <td class="userId">${one.userId}</td>
                <td class="userName">${one.userName}</td>
                <td class="userNick">${one.userNick}</td>
                <td class="phone">${one.phone}</td>
                <td class="address">${one.address}</td>
                <td><a class="btn btn-sm btn-info" href="javascript:"  onclick="delUser(${one.userId})">查看</a></td>
            </tr>
        </c:forEach>
        </tbody>
    </table>

<%--    删除用户的模态框--%>
    <div class="modal fade" id="delUserModal">
        <div class="modal-dialog">
            <div class="modal-content">

                <div class="modal-header">
                    <h5 class="modal-title">删除用户</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>

                <div class="modal-body">
                    <form id="editForm" action="/userMessage/deleteOne" method="post" onsubmit="return false;">
                        <div class="form-group">
                            <label>用户编号</label>
                            <input type="text" name="userId" id="userId"  class="form-control" readonly>
                        </div>
                        <div class="form-group">
                            <label>用户名称</label>
                            <input type="text" name="userName" id="userName"  class="form-control" readonly>
                        </div>
                        <div class="form-group">
                            <label>用户昵称</label>
                            <input type="text" name="userNick" id="userNick" class="form-control" readonly>
                        </div>
                        <div class="form-group">
                            <label>联系电话</label>
                            <input type="text" name="phone" id="phone" class="form-control" readonly>
                        </div>
                        <div class="form-group">
                            <label>收货地址</label>
                            <input type="text" name="address" id="address" class="form-control" readonly>
                        </div>
                    </form>
                </div>

                <div class="modal-footer">
                    <button type="button" class="btn btn-primary" onclick="doDelete(${one.userId})">删除</button>
                </div>

            </div>
        </div>
    </div>
</div>
<script>
    function delUser(userId) {
        $("#delUserModal").modal("show");
        $("#userId").val($("#b_" + userId + " .userId").text());
        $("#userName").val($("#b_" + userId + " .userName").text());
        $("#userNick").val($("#b_" + userId + " .userNick").text());
        $("#phone").val($("#b_" + userId + " .phone").text());
        $("#address").val($("#b_" + userId + " .address").text());
    }

    function doDelete() {
        <%--if (confirm("你真的要删除吗？")){--%>
        <%--    &lt;%&ndash;location.href="${pageContext.request.contextPath}op/delete?goodsId="+userId;&ndash;%&gt;--%>
        <%--    location.href="${pageContext.request.contextPath}/userManager/deleteOne?userId="+userId;--%>
        <%--}--%>
        $.ajax({
            url:"deleteOne",
            method:"post",
            data:{
                userId:$("#userId").val(),
            },
            success:function (data) {
                console.log(data);
                if(data != null) {
                    alert("修改成功");
                    location.reload();
                }
                else alert("修改失败");
            },
            error:function (e) {
                console.log(e);
                console.log("通讯错误");
            }
        });
    }
</script>
</body>
</html>
